/*
 * @Descripttion: 
 * @version: 
 * @Author: lily
 * @Date: 2021-03-26 10:09:00
 * @LastEditors: lily
 * @LastEditTime: 2021-03-26 11:08:37
 */
/*
 * @lc app=leetcode.cn id=682 lang=javascript
 *
 * [682] 棒球比赛
 */

// @lc code=start
/**
 * @param {string[]} ops
 * @return {number}
 */
var calPoints = function (ops) {
    let newArr = []
    ops.forEach((op) => {
        switch (op) {
            case "C":
                newArr.pop()
                break;

            case "D":
                newArr.push(newArr[newArr.length - 1] * 2)
                break;

            case "+":
                newArr.push(newArr[newArr.length - 2] + newArr[newArr.length - 1])
                break;
            default:
                newArr.push(op * 1)
                break;
        }
    })
    return newArr.reduce((i, j) => { return i + j })
};
// @lc code=end

calPoints(["5", "2", "C", "D", "+"])